package com.dstz.demo.rest.controller;

import com.dstz.base.api.response.impl.ResultMsg;
import com.dstz.demo.core.manager.*;
import com.dstz.demo.core.model.*;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/api")
public class ApiController {

    @Autowired
    private ContentManager contentManager;
    @Autowired
    private FeedbackManager feedbackManager;
    @Autowired
    private BusRecordManager busRecordManager;
    @Autowired
    private PayTypeManager payTypeManager;
    @Autowired
    private UserHealthManager userHealthManager;
    @Autowired
    private TuserManager tuserManager;
    @Autowired
    private StationLinestoreManager stationLinestoreManager;

    //获取帮助中心问题列表
    @GetMapping("/getHelpList")
    @ResponseBody
    public ResultMsg getHelpList() {

        List<Content> contents = contentManager.findHelpList();
        return ResultMsg.SUCCESS(contents);
    }

    //获取关于我们信息
    @GetMapping("/getAboutUs")
    @ResponseBody
    public ResultMsg getAboutUs() {

        Content content= contentManager.findAboutUs();
        return ResultMsg.SUCCESS(content);
    }

    @GetMapping("/getListByTitle")
    @ResponseBody
    public ResultMsg getListByTitle(@RequestParam(value = "title") String title) {

        if (StringUtils.isBlank(title) || title == null) {
            return ResultMsg.ERROR("输入参数为空 !");
        }
        List<Content> contents = contentManager.findByTitle(title);
        return ResultMsg.SUCCESS(contents);
    }

    @GetMapping("/getFeedbacksByUserId")
    @ResponseBody
    public ResultMsg getFeedbacksByUserId(@RequestParam(value = "userId") Integer userId) {

        if (userId == null) {
            return ResultMsg.ERROR("输入参数为空 !");
        }
        List<Feedback> feedbacks = feedbackManager.findByUserId(userId);
        return ResultMsg.SUCCESS(feedbacks);
    }

    @GetMapping("/getBusRecordsByUserId")
    @ResponseBody
    public ResultMsg getBusRecordsByUserId(@RequestParam(value = "userId") Integer userId) {

        if (userId == null) {
            return ResultMsg.ERROR("输入参数为空 !");
        }
        List<BusRecord> busRecords = busRecordManager.findByUserId(userId);
        return ResultMsg.SUCCESS(busRecords);
    }

    //获取用户支付方式
    @GetMapping("/getPayTypes")
    @ResponseBody
    public ResultMsg getPayTypes(@RequestParam(value = "userId") Integer userId) {

        if (userId == null) {
            return ResultMsg.ERROR("输入参数为空 !");
        }
        List<PayType> payTypes = payTypeManager.findByUserId(userId);
        return ResultMsg.SUCCESS(payTypes);
    }

    //新增用户健康申报信息
    @PostMapping("/saveUserHealth")
    @ResponseBody
    public ResultMsg saveUserHealth(@RequestBody UserHealth userHealth) {

        if (userHealth == null) {
            return ResultMsg.ERROR("输入参数不存在userHealth :" +userHealth);
        }
        userHealthManager.create(userHealth);
        return ResultMsg.SUCCESS("操作成功");
    }

    //获取个人信息
    @GetMapping("/getUserDetail")
    @ResponseBody
    public ResultMsg getUserDetail(@RequestParam(value = "id") Integer id) {

        Tuser user = tuserManager.findById(id);
        return ResultMsg.SUCCESS(user);
    }

    //获取线路收藏
    @GetMapping("/getStationLinestore")
    @ResponseBody
    public ResultMsg getStationLinestore(@RequestParam(value = "id") Integer id) {

        StationLinestore linestore = stationLinestoreManager.findById(id);
        return ResultMsg.SUCCESS(linestore);
    }
}
